<?php
namespace app\index\controller;
use think\Controller;
use think\Session;
use think\Request;
use think\View;
use think\Db;
use app\index\validate\Valid;
use PHPExcel;
use PHPExcel_Writer_Excel5;
use PHPExcel_Style_Alignment;
use PHPExcel_Style_Fill;
use PHPExcel_Style_Border;

class Tifyhxmdcx extends Common
{

	//列表--非常规和进场
    public function index()
    {

        $where = [];
        $sn = $this->request->get('sn');
        $this->assign('sn',$sn);
        $zoning = $this->request->get('zoning');
        $this->assign('zoning',$zoning);
        $jxs_title = $this->request->get('jxs_title');
        $this->assign('jxs_title',$jxs_title);
        $start = $this->request->get('start');
        $this->assign('start',$start);
        $end = $this->request->get('end');
        $this->assign('end',$end);
        $provice = $this->request->get('provice');
        $this->assign('provice',$provice);
        $status = $this->request->get('status');
        $this->assign('status',$status);
        $cusername = $this->request->get('cusername');
        $this->assign('cusername',$cusername);

        if($sn){
            $where['sn'] = ['like',"%{$sn}%"];
        }
        if($start&&$end){
            $where['ctime'] = ['between',[strtotime($start),strtotime($end)]];
        }elseif($start){
            $where['ctime'] = ['>',strtotime($start)];
        }elseif($end){
            $where['ctime'] = ['<',strtotime($end)];
        }

        if($provice&&$jxs_title){
            $pids = db('cg_market_provice')
                ->where('title','like',"%{$provice}%")
                ->column('id');
            $jxsids = db('cg_jxs')
                ->where('provice','in',$pids)
                ->column('id');
            $jxsids2 = db('cg_jxs')->where('title','like',"%{$jxs_title}%")->column('id');
            $where['jxs_id'] = [['in',$jxsids],['in',$jxsids2],'and'];
        }elseif($zoning&&$jxs_title){
            $zids = db('cg_market_zoning')
                ->where('title','like',"%{$zoning}%")
                ->column('id');
            $jxsids = db('cg_jxs')
                ->where('zoning','in',$zids)
                ->column('id');
            $jxsids2 = db('cg_jxs')->where('title','like',"%{$jxs_title}%")->column('id');
            $where['jxs_id'] = [['in',$jxsids],['in',$jxsids2],'and'];
        }elseif($zoning&&$provice){
            $pids = db('cg_market_provice')
                ->where('title','like',"%{$provice}%")
                ->column('id');
            $jxsids = db('cg_jxs')
                ->where('provice','in',$pids)
                ->column('id');
            $where['jxs_id'] = ['in',$jxsids];
        }elseif($zoning){
            $zids = db('cg_market_zoning')
                ->where('title','like',"%{$zoning}%")
                ->column('id');
            $jxsids = db('cg_jxs')
                ->where('zoning','in',$zids)
                ->column('id');
            $where['jxs_id'] = ['in',$jxsids];
        }elseif($provice){
            $pids = db('cg_market_provice')
                ->where('title','like',"%{$provice}%")
                ->column('id');
            $jxsids = db('cg_jxs')
                ->where('provice','in',$pids)
                ->column('id');
            $where['jxs_id'] = ['in',$jxsids];
        }elseif($jxs_title){
            $jxsids = db('cg_jxs')->where('title','like',"%{$jxs_title}%")->column('id');
            $where['jxs_id'] = ['in',$jxsids];
        }
        if($status!=null){
            $where['status'] = $status;
        }
        if($cusername){
            $cuserids = db('employee')->where('em_name','like',"%{$cusername}%")->column('id');
            $where['cuser'] = ['in',$cuserids];
        }

        $count = Db::table('cg_ti_hexiao t')->where($where)->count();
        $data = Db::table('cg_ti_hexiao t')->order("t.id desc")->where($where)->paginate(10,$count);
//        echo Db::table('cg_ti')->getLastSql();
        $page = $data->render();
        $data = $data->items();
        foreach($data as $k=>$v){
            $v['jxs_title'] = db('cg_jxs')->where('id',$v['jxs_id'])->value('title');
            $v['cusername'] = Db::table('employee')->where(array('id'=>$v['cuser']))->value('em_name');
            $v['pusername'] = Db::table('employee')->where(array('id'=>$v['puser']))->value('em_name');
            $v['ctime'] = date('Y-m-d H:i',$v['ctime']);
            $v['ptime'] = date('Y-m-d H:i',$v['ptime']);
            $v['status_title'] = db('cg_ti_hexiao_status')->where('id',$v['status'])->value('title');

            //反馈完成之后才能显示核销按钮
            $data[$k] = $v;
        }

        $this->assign('data',$data);
        $this->assign('page',$page);

        $hexiao_status = db('cg_ti_hexiao_status')->select();
        $this->assign('hexiao_status',$hexiao_status);
        return $this->fetch();
    }

    //导出excel--非常规和进场
    public function excel(){
        $where = [];
        $sn = $this->request->get('sn');
        $this->assign('sn',$sn);
        $zoning = $this->request->get('zoning');
        $this->assign('zoning',$zoning);
        $jxs_title = $this->request->get('jxs_title');
        $this->assign('jxs_title',$jxs_title);
        $start = $this->request->get('start');
        $this->assign('start',$start);
        $end = $this->request->get('end');
        $this->assign('end',$end);
        $provice = $this->request->get('provice');
        $this->assign('provice',$provice);
        $status = $this->request->get('status');
        $this->assign('status',$status);
        $cusername = $this->request->get('cusername');
        $this->assign('cusername',$cusername);

        if($sn){
            $where['sn'] = ['like',"%{$sn}%"];
        }
        if($start&&$end){
            $where['ctime'] = ['between',[strtotime($start),strtotime($end)]];
        }elseif($start){
            $where['ctime'] = ['>',strtotime($start)];
        }elseif($end){
            $where['ctime'] = ['<',strtotime($end)];
        }

        if($provice&&$jxs_title){
            $pids = db('cg_market_provice')
                ->where('title','like',"%{$provice}%")
                ->column('id');
            $jxsids = db('cg_jxs')
                ->where('provice','in',$pids)
                ->column('id');
            $jxsids2 = db('cg_jxs')->where('title','like',"%{$jxs_title}%")->column('id');
            $where['jxs_id'] = [['in',$jxsids],['in',$jxsids2],'and'];
        }elseif($zoning&&$jxs_title){
            $zids = db('cg_market_zoning')
                ->where('title','like',"%{$zoning}%")
                ->column('id');
            $jxsids = db('cg_jxs')
                ->where('zoning','in',$zids)
                ->column('id');
            $jxsids2 = db('cg_jxs')->where('title','like',"%{$jxs_title}%")->column('id');
            $where['jxs_id'] = [['in',$jxsids],['in',$jxsids2],'and'];
        }elseif($zoning&&$provice){
            $pids = db('cg_market_provice')
                ->where('title','like',"%{$provice}%")
                ->column('id');
            $jxsids = db('cg_jxs')
                ->where('provice','in',$pids)
                ->column('id');
            $where['jxs_id'] = ['in',$jxsids];
        }elseif($zoning){
            $zids = db('cg_market_zoning')
                ->where('title','like',"%{$zoning}%")
                ->column('id');
            $jxsids = db('cg_jxs')
                ->where('zoning','in',$zids)
                ->column('id');
            $where['jxs_id'] = ['in',$jxsids];
        }elseif($provice){
            $pids = db('cg_market_provice')
                ->where('title','like',"%{$provice}%")
                ->column('id');
            $jxsids = db('cg_jxs')
                ->where('provice','in',$pids)
                ->column('id');
            $where['jxs_id'] = ['in',$jxsids];
        }elseif($jxs_title){
            $jxsids = db('cg_jxs')->where('title','like',"%{$jxs_title}%")->column('id');
            $where['jxs_id'] = ['in',$jxsids];
        }
        if($status){
            $where['status'] = $status;
        }
        if($cusername){
            $cuserids = db('employee')->where('em_name','like',"%{$cusername}%")->column('id');
            $where['cuser'] = ['in',$cuserids];
        }


        $data = Db::table('cg_ti_hexiao t')->order("t.id desc")->where($where)->select();
        foreach($data as $k=>$v){
            $v['jxs_title'] = db('cg_jxs')->where('id',$v['jxs_id'])->value('title');
            $v['cusername'] = Db::table('employee')->where(array('id'=>$v['cuser']))->value('em_name');
            $v['pusername'] = Db::table('employee')->where(array('id'=>$v['puser']))->value('em_name');
            $v['ctime'] = date('Y-m-d H:i',$v['ctime']);
            $v['ptime'] = date('Y-m-d H:i',$v['ptime']);
            $v['status_title'] = db('cg_ti_hexiao_status')->where('id',$v['status'])->value('title');
            //反馈完成之后才能显示核销按钮
            $data[$k] = $v;
        }
        Vendor("PHPExcel");
        Vendor("PHPExcel.Writer.Excel5");
        $objPHPExcel= new PHPExcel();
        $objProps=$objPHPExcel->getProperties();

        $objProps->setCreator('admin');
        $objProps->setLastModifiedBy('admin');
        $objProps->setTitle('Office 2003 XLSX Test Document');
        $objProps->setSubject('Office 2003 XLSX Test Document');
        $objProps->setDescription("Test document, generated by PHPExcel.");
        $objProps->setKeywords("office excel PHPExcel");
        $objProps->setCategory("Test");

        $objPHPExcel->setActiveSheetIndex(0);
        $as =  $objPHPExcel->getActiveSheet();
        $as->setTitle("销售费用核销申请");
        $styleArray = array(
            'borders' => array(
                'allborders' => array(
                    //'style' => PHPExcel_Style_Border::BORDER_THICK,//边框是粗的
                    'style' => PHPExcel_Style_Border::BORDER_THIN,//细边框
                    'color' => array('argb' => ''),
                ),
            ),
        );
        $as->mergeCells('A1:G1');
        $as->setCellValue('A1','TI费用核销面单申请');
        //加粗
        $as->getStyle('A1')->getFont()->setBold(true);
        //字体
        $as->getStyle('A1')->getFont()->setSize(14);
        $as->mergeCells('A2:G2');
        $username = db('employee')->where('id',session('employee_id'))->value('em_name');
        $as->setCellValue('A2','注：本表单由软件导出，导出时间：'.date('Y-m-d H:i').'导出人：'.$username);
        $as->getStyle('A1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $as->getStyle('A2')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);

        //标题
        $as->getStyle('A3:G3')->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
        $as->getStyle('A3:G3')->getFill()->getStartColor()->setARGB('0099CCFF');
        $as->setCellValue('A3','No.');
        $as->setCellValue('B3','编号');
        $as->setCellValue('C3','主题');
        $as->setCellValue('D3','核销金额');
        $as->setCellValue('E3','状态');
        $as->setCellValue('F3','申请人');
        $as->setCellValue('G3','申请时间');

        foreach($data as $k=>$v){
            $n = 4+$k;
            $as->setCellValue('A'.$n,$k+1);
            $as->setCellValue('B'.$n,''.$v['sn']);
            $title = '核销申请'.$v['jxs_title'];
            if($v['status']==7){
                $title .= '(已生效)';
            }
            $as->setCellValue('C'.$n,$title);
            $as->setCellValue('D'.$n,$v['tax']);
            $as->setCellValue('E'.$n,$v['status_title']);
            $as->setCellValue('F'.$n,$v['cusername']);
            $as->setCellValue('G'.$n,$v['ctime']);
        }

        $n = $as->getHighestRow();
        $as->getStyle('A1:G'.$n)->applyFromArray($styleArray);
        $objWriter = new PHPExcel_Writer_Excel5($objPHPExcel);
        ob_end_clean();
        header("Pragma: public");
        header("Expires:0");
        header("Cache-Control:must-revalidate, post-check=0, pre-check=0");
        header("Content-Type:application/force-download");
        header("Content-Type:application/vnd.ms-execl");
        header("Content-Type:application/octet-stream");
        header("Content-Type:application/download");
        header('Content-Disposition:attachment;filename=完整版.xls');
        header("Content-type:text/html;charset=utf-8");
        header("Content-Transfer-Encoding:binary");
        $objWriter->save('php://output');

    }

    //列表--常规
    public function cgindex()
    {
        $where = [];
        $sn = $this->request->get('sn');
        $this->assign('sn',$sn);
        $zoning = $this->request->get('zoning');
        $this->assign('zoning',$zoning);
        $jxs_title = $this->request->get('jxs_title');
        $this->assign('jxs_title',$jxs_title);
        $start = $this->request->get('start');
        $this->assign('start',$start);
        $end = $this->request->get('end');
        $this->assign('end',$end);
        $provice = $this->request->get('provice');
        $this->assign('provice',$provice);
        $status = $this->request->get('status');
        $this->assign('status',$status);
        $cusername = $this->request->get('cusername');
        $this->assign('cusername',$cusername);

        if($sn){
            $where['no'] = ['like',"%{$sn}%"];
        }
        if($start&&$end){
            $where['created_on'] = ['between',[strtotime($start),strtotime($end)]];
        }elseif($start){
            $where['created_on'] = ['>',strtotime($start)];
        }elseif($end){
            $where['created_on'] = ['<',strtotime($end)];
        }

        if($provice&&$jxs_title){
            $pids = db('cg_market_provice')
                ->where('title','like',"%{$provice}%")
                ->column('id');
            $jxsids = db('cg_jxs')
                ->where('provice','in',$pids)
                ->column('id');
            $jxsids2 = db('cg_jxs')->where('title','like',"%{$jxs_title}%")->column('id');
            $where['jxs_id'] = [['in',$jxsids],['in',$jxsids2],'and'];
        }elseif($zoning&&$jxs_title){
            $zids = db('cg_market_zoning')
                ->where('title','like',"%{$zoning}%")
                ->column('id');
            $jxsids = db('cg_jxs')
                ->where('zoning','in',$zids)
                ->column('id');
            $jxsids2 = db('cg_jxs')->where('title','like',"%{$jxs_title}%")->column('id');
            $where['jxs_id'] = [['in',$jxsids],['in',$jxsids2],'and'];
        }elseif($zoning&&$provice){
            $pids = db('cg_market_provice')
                ->where('title','like',"%{$provice}%")
                ->column('id');
            $jxsids = db('cg_jxs')
                ->where('provice','in',$pids)
                ->column('id');
            $where['jxs_id'] = ['in',$jxsids];
        }elseif($zoning){
            $zids = db('cg_market_zoning')
                ->where('title','like',"%{$zoning}%")
                ->column('id');
            $jxsids = db('cg_jxs')
                ->where('zoning','in',$zids)
                ->column('id');
            $where['jxs_id'] = ['in',$jxsids];
        }elseif($provice){
            $pids = db('cg_market_provice')
                ->where('title','like',"%{$provice}%")
                ->column('id');
            $jxsids = db('cg_jxs')
                ->where('provice','in',$pids)
                ->column('id');
            $where['jxs_id'] = ['in',$jxsids];
        }elseif($jxs_title){
            $jxsids = db('cg_jxs')->where('title','like',"%{$jxs_title}%")->column('id');
            $where['jxs_id'] = ['in',$jxsids];
        }
        if($status){
            $where['state'] = $status;
        }
        if($cusername){
            $cuserids = db('employee')->where('em_name','like',"%{$cusername}%")->column('id');
            $where['c_user_id'] = ['in',$cuserids];
        }

        $count = Db::table('ti_hexiao_apply t')->where($where)->count();
        $data = Db::table('ti_hexiao_apply t')->order("t.id desc")->where($where)->paginate(10,$count);
//        echo Db::table('cg_ti')->getLastSql();
        $page = $data->render();
        $data = $data->items();
        foreach($data as $k=>$v){
            $v['cusername'] = Db::table('employee')->where(array('id'=>$v['c_user_id']))->value('em_name');
            $v['ctime'] = $v['created_on'];
            $v['status_title'] = db('cg_ti_hexiao_status')->where('id',$v['state'])->value('title');
            //查询经销商
            $jxs_id = db('ti_hexiao_detail t')
                ->join('ti_apply_detail t2','t.detail_id=t.id')
                ->join('ti_apply t3','t3.id=t2.apply_id')
                ->where(['t.hexiao_id'=>$v['id']])
                ->value('jxs_id');
            $v['jxs_title'] = db('cg_jxs')->where('id',$jxs_id)->value('title');
            $v['tax'] = db('ti_hexiao_detail')->where('hexiao_id',$v['id'])->sum('hexiao_weishui');
            $data[$k] = $v;
        }

        $this->assign('data',$data);
        $this->assign('page',$page);

        return $this->fetch();
    }

    //导出excel--常规
    public function cgexcel(){
        $where = [];
        $sn = $this->request->get('sn');
        $this->assign('sn',$sn);
        $zoning = $this->request->get('zoning');
        $this->assign('zoning',$zoning);
        $jxs_title = $this->request->get('jxs_title');
        $this->assign('jxs_title',$jxs_title);
        $start = $this->request->get('start');
        $this->assign('start',$start);
        $end = $this->request->get('end');
        $this->assign('end',$end);
        $provice = $this->request->get('provice');
        $this->assign('provice',$provice);
        $status = $this->request->get('status');
        $this->assign('status',$status);
        $cusername = $this->request->get('cusername');
        $this->assign('cusername',$cusername);

        if($sn){
            $where['no'] = ['like',"%{$sn}%"];
        }
        if($start&&$end){
            $where['created_on'] = ['between',[strtotime($start),strtotime($end)]];
        }elseif($start){
            $where['created_on'] = ['>',strtotime($start)];
        }elseif($end){
            $where['created_on'] = ['<',strtotime($end)];
        }

        if($provice&&$jxs_title){
            $pids = db('cg_market_provice')
                ->where('title','like',"%{$provice}%")
                ->column('id');
            $jxsids = db('cg_jxs')
                ->where('provice','in',$pids)
                ->column('id');
            $jxsids2 = db('cg_jxs')->where('title','like',"%{$jxs_title}%")->column('id');
            $where['jxs_id'] = [['in',$jxsids],['in',$jxsids2],'and'];
        }elseif($zoning&&$jxs_title){
            $zids = db('cg_market_zoning')
                ->where('title','like',"%{$zoning}%")
                ->column('id');
            $jxsids = db('cg_jxs')
                ->where('zoning','in',$zids)
                ->column('id');
            $jxsids2 = db('cg_jxs')->where('title','like',"%{$jxs_title}%")->column('id');
            $where['jxs_id'] = [['in',$jxsids],['in',$jxsids2],'and'];
        }elseif($zoning&&$provice){
            $pids = db('cg_market_provice')
                ->where('title','like',"%{$provice}%")
                ->column('id');
            $jxsids = db('cg_jxs')
                ->where('provice','in',$pids)
                ->column('id');
            $where['jxs_id'] = ['in',$jxsids];
        }elseif($zoning){
            $zids = db('cg_market_zoning')
                ->where('title','like',"%{$zoning}%")
                ->column('id');
            $jxsids = db('cg_jxs')
                ->where('zoning','in',$zids)
                ->column('id');
            $where['jxs_id'] = ['in',$jxsids];
        }elseif($provice){
            $pids = db('cg_market_provice')
                ->where('title','like',"%{$provice}%")
                ->column('id');
            $jxsids = db('cg_jxs')
                ->where('provice','in',$pids)
                ->column('id');
            $where['jxs_id'] = ['in',$jxsids];
        }elseif($jxs_title){
            $jxsids = db('cg_jxs')->where('title','like',"%{$jxs_title}%")->column('id');
            $where['jxs_id'] = ['in',$jxsids];
        }
        if($status){
            $where['state'] = $status;
        }
        if($cusername){
            $cuserids = db('employee')->where('em_name','like',"%{$cusername}%")->column('id');
            $where['c_user_id'] = ['in',$cuserids];
        }

        $data = Db::table('ti_hexiao_apply t')->order("t.id desc")->where($where)->select();
        foreach($data as $k=>$v){
            $v['cusername'] = Db::table('employee')->where(array('id'=>$v['c_user_id']))->value('em_name');
            $v['ctime'] = $v['created_on'];
            $v['status_title'] = db('cg_ti_hexiao_status')->where('id',$v['state'])->value('title');
            //查询经销商
            $jxs_id = db('ti_hexiao_detail t')
                ->join('ti_apply_detail t2','t.detail_id=t.id')
                ->join('ti_apply t3','t3.id=t2.apply_id')
                ->where(['t.hexiao_id'=>$v['id']])
                ->value('jxs_id');
            $v['jxs_title'] = db('cg_jxs')->where('id',$jxs_id)->value('title');
            $v['tax'] = db('ti_hexiao_detail')->where('hexiao_id',$v['id'])->sum('hexiao_weishui');
            $data[$k] = $v;
        }
        Vendor("PHPExcel");
        Vendor("PHPExcel.Writer.Excel5");
        $objPHPExcel= new PHPExcel();
        $objProps=$objPHPExcel->getProperties();

        $objProps->setCreator('admin');
        $objProps->setLastModifiedBy('admin');
        $objProps->setTitle('Office 2003 XLSX Test Document');
        $objProps->setSubject('Office 2003 XLSX Test Document');
        $objProps->setDescription("Test document, generated by PHPExcel.");
        $objProps->setKeywords("office excel PHPExcel");
        $objProps->setCategory("Test");

        $objPHPExcel->setActiveSheetIndex(0);
        $as =  $objPHPExcel->getActiveSheet();
        $as->setTitle("销售费用核销申请");
        $styleArray = array(
            'borders' => array(
                'allborders' => array(
                    //'style' => PHPExcel_Style_Border::BORDER_THICK,//边框是粗的
                    'style' => PHPExcel_Style_Border::BORDER_THIN,//细边框
                    'color' => array('argb' => ''),
                ),
            ),
        );
        $as->mergeCells('A1:G1');
        $as->setCellValue('A1','TI费用核销面单申请');
        //加粗
        $as->getStyle('A1')->getFont()->setBold(true);
        //字体
        $as->getStyle('A1')->getFont()->setSize(14);
        $as->mergeCells('A2:G2');
        $username = db('employee')->where('id',session('employee_id'))->value('em_name');
        $as->setCellValue('A2','注：本表单由软件导出，导出时间：'.date('Y-m-d H:i').'导出人：'.$username);
        $as->getStyle('A1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $as->getStyle('A2')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);

        //标题
        $as->getStyle('A3:G3')->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
        $as->getStyle('A3:G3')->getFill()->getStartColor()->setARGB('0099CCFF');
        $as->setCellValue('A3','No.');
        $as->setCellValue('B3','编号');
        $as->setCellValue('C3','主题');
        $as->setCellValue('D3','核销金额');
        $as->setCellValue('E3','状态');
        $as->setCellValue('F3','申请人');
        $as->setCellValue('G3','申请时间');

        foreach($data as $k=>$v){
            $n = 4+$k;
            $as->setCellValue('A'.$n,$k+1);
            $as->setCellValue('B'.$n,''.$v['no']);
            $title = '核销申请'.$v['jxs_title'];
            if($v['status']==7){
                $title .= '(已生效)';
            }
            $as->setCellValue('C'.$n,$title);
            $as->setCellValue('D'.$n,$v['tax']);
            $as->setCellValue('E'.$n,$v['status_title']);
            $as->setCellValue('F'.$n,$v['cusername']);
            $as->setCellValue('G'.$n,$v['ctime']);
        }

        $n = $as->getHighestRow();
        $as->getStyle('A1:G'.$n)->applyFromArray($styleArray);
        $objWriter = new PHPExcel_Writer_Excel5($objPHPExcel);
        ob_end_clean();
        header("Pragma: public");
        header("Expires:0");
        header("Cache-Control:must-revalidate, post-check=0, pre-check=0");
        header("Content-Type:application/force-download");
        header("Content-Type:application/vnd.ms-execl");
        header("Content-Type:application/octet-stream");
        header("Content-Type:application/download");
        header('Content-Disposition:attachment;filename=完整版.xls');
        header("Content-type:text/html;charset=utf-8");
        header("Content-Transfer-Encoding:binary");
        $objWriter->save('php://output');

    }

    //根据id查找状态
    public function status($id){
        $data = [
            0=>'草稿',
            1=>'已打回',
            3=>'区域领导审批',
            4=>'拆分人审批',
            5=>'集团领导审批',
            6=>'抄送',
            7=>'已归档',
            8=>'已作废',
            9=>'已核销',
        ];
        return $data[$id];
    }

    //返回二维数组中的某二维key的合计
    public function array_sum($arr,$key){
        $sum = 0;
        foreach($arr as $k=>$v){
            $sum += $v[$key];
        }
        return $sum;
    }
}
